package com.google.jessewilson.codesearch.util;

import ca.odell.glazedlists.EventList;

/**
 * When results arrive, add them to an EventList.
 *
 * @author jessewilson
 */
public class EventListSink<T> implements ProducerSink<T> {
  private EventList<T> sink;
  public EventListSink(EventList<T> sink) {
    this.sink = sink;
  }
  public void produced(T value) {
    sink.getReadWriteLock().writeLock().lock();
    try {
      sink.add(value);
    } finally {
      sink.getReadWriteLock().writeLock().unlock();
    }
  }
}
